<?php
class CoreGroupUserModel extends Model {
	var $_table = 'core_groupuser';
	var $gid_nr;
	var $uid_nr;
	
	public function getGroups($uid) {
		$this->alias ( "CGU" )->join ( "core_group as CG", "CGU.gid = CG.gid" );
		$groups = $this->where ( array ('uid' => $uid ) )->retrieve ( 'CG.*,CGU.gid as group_id' );
		return $groups;
	}
	public function addToGroup($uid, $gids) {
		foreach ( $gids as $gid ) {
			$data ['gid'] = $gid;
			$data ['uid'] = $uid;
			if (! $this->exist ( $data )) {
				$this->insert ( $data );
			}
		}
		return true;
	}
}